<%@ page pageEncoding="UTF-8" %>
<%@ include file="../common/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="../common/meta.jsp" %>
    <title><f:message key="common.title"/> -功能管理</title>
    <%@ include file="../common/css.jsp" %>
    <link href="${BASE}/www/js/plugins/msgGrowl/css/msgGrowl.css" rel="stylesheet">

</head>

<body>

<div id="wrapper">

<%@ include file="../common/topbar.jsp" %>
<%@ include file="../common/header.jsp" %>

<div id="masthead">

    <div class="container">

        <div class="masthead-pad">

            <div class="masthead-text">
                <h5>功能管理</h5>
            </div> <!-- /.masthead-text -->

        </div>

    </div> <!-- /.container -->

</div> <!-- /#masthead -->

<div id="content">

<div class="container">

<div class="row">

<div class="tabbable">

    <div class="span3">

        <ul class="nav nav-tabs nav-stacked">
            <li class="active">
                <a href="#tab1" data-toggle="tab">
                    <i class="icon-user"></i>
                    账号信息
                    <i class="icon-chevron-right"></i>
                </a>
            </li>
            <li>
                <a href="#tab2" data-toggle="tab">
                    <i class="icon-file"></i>
                    自定义菜单
                    <i class="icon-chevron-right"></i>
                </a>
            </li>
            <li>
                <a href="#tab3" data-toggle="tab">
                    <i class="icon-check"></i>
                    消息调试
                    <i class="icon-chevron-right"></i>
                </a>
            </li>
        </ul>

    </div> <!-- /.span3 -->


    <div class="span9">

        <div class="tab-content">

            <div class="tab-pane active" id="tab1">

                <h3>公众号设置</h3>

                <form id="account_edit_form" class="form-horizontal">
                    <fieldset>
                        <div class="form-group">
                            <div class="controls">
                                <input type="hidden" id="id" value="${account.id}">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="account">账号:</label>
                            <div class="controls">
                                <input type="text" class="input-medium disabled" id="account" name="account" value="${account.account}" disabled="">
                                <p class="help-block">账号名不可修改.</p>
                            </div>

                        </div>

                        <div class="control-group">
                            <label class="control-label" for="password">密码:</label>
                            <div class="controls">
                                <input type="text" class="input-medium" name="password" id="password" value="${account.password}">
                            </div>
                        </div>


                        <div class="control-group">
                            <label class="control-label" for="password">token:</label>
                            <div class="controls">
                                <input type="text" class="input-medium" name="token" id="token" value="${account.token}">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="appid">appid:</label>
                            <div class="controls">
                                <input type="text" class="input-medium" name="appid" id="appid" value="${account.appid}">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="appsecret">appsecret:</label>
                            <div class="controls">
                                <input type="text" class="input-medium" name="appsecret" id="appsecret" value="${account.appsecret}">
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-default">
                                <f:message key="common.save" />
                            </button>
                            <button type="button" id="back" class="btn btn-default">
                                <f:message key="common.back" />
                            </button>
                        </div>


                    </fieldset>
                </form>

            </div> <!-- /#tab1 -->


            <div class="tab-pane" id="tab2">

                <h3>自定义菜单</h3>

                <form id="menu_edit_form" class="form-horizontal">
                    <fieldset>

                        <div class="control-group">

                            <label class="control-label" for="account">菜单（JSON):</label>
                            <div class="controls">
                                <textarea class="span6" name="message" id="message" rows="20"></textarea>
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="button" id="getMenu" class="btn btn-primary">
                                获取菜单
                            </button>
                            <button type="submit" class="btn btn-default">
                                更新菜单
                            </button>
                            <button type="button" id="deleteMenu" class="btn btn-primary">
                                删除菜单
                            </button>

                        </div>

                    </fieldset>
                </form>

            </div> <!-- /#tab2 -->

            <div class="tab-pane" id="tab3">

                <h3>消息调试</h3>

                <form id="message_edit_form" class="form-horizontal">

                    <fieldset>

                        <div class="control-group">
                            <label class="control-label" for="message">自定义消息:</label>
                            <div class="controls">
                                <select id="msgType" name="MsgType" onchange="msgFn(this)">
                                    <option value="">选择消息类型</option>
                                    <option value="text">文本消息</option>
                                    <option value="image">图片消息</option>
                                    <option value="voice">语音消息</option>
                                    <option value="video">视频消息</option>
                                    <option value="location">地理位置消息</option>
                                    <option value="link">链接消息</option>
                                    <option value="event_click">菜单点击事件</option>
                                    <option value="event_view">菜单点击跳转事件</option>
                                    <option value="event_subscribe">订阅事件</option>
                                    <option value="event_unsubscribe">取消订阅</option>
                                    <option value="event_location">获取用户位置信息</option>

                                </select>
                            </div>

                        </div>

                        <div class="control-group">
                            <label class="control-label" for="inMessage">发送内容:</label>
                            <div class="controls">
                                <textarea class="span6" name="inMessage" id="inMessage" rows="8"></textarea>
                            </div>
                        </div>
                        <label class="control-label" for="outMessage">接收内容:</label>
                        <div class="controls">
                            <textarea class="span6" name="outMessage" id="outMessage" rows="8"></textarea>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary"> 提交 </button>
                        </div>

                    </fieldset>
                </form>

            </div> <!-- /#tab3 -->
       </div> <!-- /.tab-content -->

    </div> <!-- /.span9 -->

</div> <!-- /.tabbable -->

</div> <!-- /.row -->


</div> <!-- /.container -->

</div> <!-- /#content -->

</div> <!-- /#wrapper -->



<%@ include file="../common/footer.jsp" %>
<%@ include file="../common/js.jsp" %>
<script src="${BASE}/www/js/plugins/msgGrowl/js/msgGrowl.js"></script>

<script type="text/javascript">
    $(function() {
        /*-------------------账号信息修改----------------------------------------*/
        $('#account_edit_form').ajaxForm({
            type: 'put',
            url: BASE + '/account/' + $('#id').val(),
            dataType: 'json',
            beforeSubmit: function() {
                return Smart.Validator.checkRequired('account_edit_form');
            },
            success: function(result) {
                if (result.success) {
                    $.msgGrowl ({
                        type: 'success'
                        , title: '提示'
                        , text: '账号信息更新成功.'
                    });
                    //location.href = BASE + '/accounts';
                }else{
                    $.msgGrowl ({
                        type: 'error'
                        , title: '提示'
                        , text: '账号信息更新失败.'
                    });
                }
            }
        });

        $('#save').click(function() {
            $('#account_edit_form').submit();
        });

        $('#back').click(function() {
            location.href = BASE + '/accounts';
        });
        /*--------------------------自定义菜单--------------------------------*/
        $('#menu_edit_form').ajaxForm({
            type: 'post',
            url: BASE + '/account/menu/' +'${account.id}',
            dataType: 'json',
            beforeSubmit: function() {
                return Smart.Validator.checkRequired('menu_edit_form');
            },
            success: function(result) {
                if (result.success) {
                    $.msgGrowl ({
                        type: 'success'
                        , title: '提示'
                        , text: '自定义菜单更新成功.'
                    });
                }else{
                    $.msgGrowl ({
                        type: 'error'
                        , title: '提示'
                        , text: '自定义菜单更新失败.'
                    });
                }
            }
        });

        var getMenuFn=function(){
            $.ajax({
                type: 'get',
                url: BASE + '/account/menu/' +'${account.id}',
                dataType: 'json',
                beforeSubmit: function() {
                    return Smart.Validator.checkRequired('menu_edit_form');
                },
                success: function(result) {
                    if (result.success) {
                        $('#message').val(result.data);
                    }
                }
            });
        };
        $('#getMenu').click(getMenuFn);

        var deleteMenuFn=function(){
            $.ajax({
                type: 'delete',
                url: BASE + '/account/menu/' +'${account.id}',
                dataType: 'json',
                beforeSubmit: function() {
                    return Smart.Validator.checkRequired('menu_edit_form');
                },
                success: function(result) {
                    if (result.success) {
                        if (result.success) {
                            $.msgGrowl ({
                                type: 'success'
                                , title: '提示'
                                , text: '自定义菜单删除成功.'
                            });
                        }else{
                            $.msgGrowl ({
                                type: 'error'
                                , title: '提示'
                                , text: '自定义菜单删除成功.'
                            });
                        }
                    }
                }
            });
        };
        $('#deleteMenu').click(deleteMenuFn);

        /*-----------------------消息调试----------------------------------------*/
        $('#message_edit_form').ajaxForm({
            type: 'post',
            url: BASE + '/debug/'+${account.id},
            dataType: 'json',
            beforeSubmit: function() {
                return Smart.Validator.checkRequired('message_edit_form');
            },
            success: function(result) {
                if (result.success) {
                    $('#outMessage').val(result.data);
                }
            }
        });

        msgFn=function(obj){
            $.ajax({
                type: 'get',
                url: BASE + '/account/message/' + obj.value,
                dataType: 'json',
                beforeSubmit: function() {
                    return Smart.Validator.checkRequired('message_edit_form');
                },
                success: function(result) {
                    if (result.success) {
                        $('#inMessage').val(result.data);
                    }
                }
            });

        };

    });
</script>

<script>
    $(function () {
        $("#nav2").addClass("active").sibling.removeClass("active");
    });
</script>

</body>
</html>